<?php
namespace app\admin\model;
use think\Model;
use think\Db;
class Equipgroup extends Model
{
    private $fields = array('group_name','rules', 'time_min');
    protected $table = 'tp_equip_group';

    function mainAllList(){
        $where[] = ['status','=',1];
        $list = $this->where($where)->order('id desc')->select();

        return $list;
    }

    //处理参数
    function disposeData($data,$act=''){

        $newData = array_elements($this->fields, $data);

        return $newData;
    }

    public function getTreeData($type='tree',$order='',$name='name',$child='id',$parent='pid'){
        // 判断是否需要排序
        if(empty($order)){
            $data=$this->where('status = 1')->select();
        }else{
            $data=$this->where('status = 1')->order($order.' is null,'.$order)->select();
        }
        // 获取树形或者结构数据
        if($type=='tree'){
            $data=Data::tree($data,$name,$child,$parent);
        }elseif($type=="level"){
            $data=Data::channelLevel($data,0,'&nbsp;',$child);
            // dump($data);
        }

        return $data;
    }

}